package com.aptoto.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;




/**
 * <pre>
 * Spring MVC配置。
 * WebMvcConfigurerAdapter：定义回调方法来定制基于注解的Spring MVC，需要注解@EnableWebMvc。
 * WebSocketConfigurer：定义回调方法来配置WebSocket，需要注解@EnableWebMvc。
 * </pre>
 * 
 * @author tongyufu
 * 
 */
@Configuration
@EnableWebSocket
@ImportResource(value = { "classpath:/spring-mvc.xml" })
public class WebConfig  implements WebSocketConfigurer {


    @Autowired
    private com.aptoto.demo.handler.redisClusterhandler   redisClusterhandler;

    /**
     * 注册WebSocket处理程序，包含SockJS。<br />
     * <br />
     * {@inheritDoc}
     */
   /* @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 原生 WebSocket
        registry.addHandler(echoWebSocketHandler(), "/echo", "/echo-issue4");
        // SockJS
        registry.addHandler(echoWebSocketHandler(), "/sockjs/echo").withSockJS();
        registry.addHandler(echoWebSocketHandler(), "/sockjs/echo-issue4").withSockJS()
            .setHttpMessageCacheSize(20000);

        registry.addHandler(redisClusterhandler, "/sockjs/cluster").withSockJS();
    }*/

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    	registry.addHandler(redisClusterhandler, "/sockjs/cluster").setAllowedOrigins("*").withSockJS();
    	System.out.println(23);
    }
    @Bean
    public Object getObject(){
    	System.out.println("**************");
    	return new Object();
    }
}
